package com.berkeley.db.berkeleydb;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.awt.*;
import java.util.ArrayList;

@SpringBootApplication
@RestController
public class BerkeleydbApplication {

	@Autowired
	RestTemplateBuilder restTemplateBuilder;

	@Bean
	public RestTemplate getRestTemplate(){
		return restTemplateBuilder.build();
	}

/*	@Bean
	public RestTemplate restTemplate() {
		HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
		httpRequestFactory.setConnectionRequestTimeout(30 * 1000);
		httpRequestFactory.setConnectTimeout(30 * 3000);
		httpRequestFactory.setReadTimeout(30 * 3000);
		return new RestTemplate(httpRequestFactory);
	}*/

	@Autowired
	private RestTemplate restTemplate;

	@GetMapping
	public ResponseEntity test(){
		String url="http://localhost:8080/bim/bimserver/projectUser/queryAllProjectUserList?projectId=af2c55f4527943bf910a";
		HttpHeaders headers = new HttpHeaders();
		headers.add(HttpHeaders.AUTHORIZATION,"Basic "+"1111");
		headers.add(HttpHeaders.ACCEPT, MediaType.ALL_VALUE);
		headers.add(HttpHeaders.CONTENT_TYPE, "application/json;charset=UTF-8");
		headers.add("userId","1111");
		ResponseEntity<ArrayList> resEntity = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(headers), ArrayList.class);

		return resEntity;
	}


	public static void main(String[] args) {
		SpringApplication.run(BerkeleydbApplication.class, args);
	}

}
